const xml2js = require('xml2js');
const fs = require('fs');

var xmlBuilder = new xml2js.Builder();

var readJson = fs.createReadStream('city.json');

var data = '';
var cnt = 0;

readJson.on('data', function(err, result){
    // console.log(result);
    cnt +=1;
    data += result;
    console.log('第' + cnt + '次读入');// +  Buffer.byteLength(result) + '字节。');
    if(err) console.log(err.message);
    console.log(result);

})

readJson.on('end',function(){
    var xml = xmlBuilder.buildObject(data);
    var writeJson = fs.createWriteStream('cityCopy.xml');
    writeJson.write(xml);
    writeJson.end();
});